package cn.yr.system.service.impl;

import cn.yr.common.core.domain.entity.SysUserRole;
import cn.yr.system.mapper.SysUserRoleMapper;
import cn.yr.system.service.ISysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Lang 1102076808@qq.com
 * @description 用户权限
 * @date 2020-07-18 00:19
 */
@Service("sysUserRoleService")
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

	@Autowired
	private SysUserRoleMapper sysUserRoleMapper;

	@Transactional(rollbackFor=Exception.class)
	@Override
	public void updateUserRole(List<SysUserRole> sysUserRoles) {
		Long[] userIds = sysUserRoles.stream().map(SysUserRole::getUserId).toArray(Long[]::new);
		sysUserRoleMapper.deleteUserRole(userIds);
		this.saveBatch(sysUserRoles);
	}
}
